//
//  AppDelegate.m
//  projectBase
//
//  Created by zhuangzhh on 14-9-11.
//  Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved.
//

#import "AppDelegate.h"
#import <AlipaySDK/AlipaySDK.h>
//APP端签名相关头文件
#import "payRequsestHandler.h"
//服务端签名只需要用到下面一个头文件
//#import "ApiXml.h"
#import <QuartzCore/QuartzCore.h>
#import "MobClick.h"
//#import "UMSocial.h"
//#import "UMSocialAccountManager.h"


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    /* 设置友盟appkey */
    [[UMSocialManager defaultManager] setUmSocialAppkey:UmengAppkey];

    [self configUSharePlatforms];
    
    
//    [NSThread sleepForTimeInterval:1.5];
    
    //[UMSocialData setAppKey:@"563c4af467e58e523600246e"];
    
    //[UMSocialQQHandler setQQWithAppId:@"1105954597" appKey:@"pMZzF2o5LZOlgAeu" url:@"http://112.124.115.55/html/index.html"];
    //    //设置支持没有客户端情况下使用SSO授权
    //[UMSocialQQHandler setSupportWebView:YES];
    
    //[MobClick startWithAppkey:UmengAppkey reportPolicy:BATCH  channelId:nil];
    //[UMSocialWechatHandler setWXAppId:@"wxa5c6354c09fa7840" appSecret:@"083cfff84bb08f31eadc97bef9708029" url:@"http://112.124.115.55/html/index.html"];
//    [WXApi registerApp:@"wxa5c6354c09fa7840"];
    //[WXApi registerApp:@"wxa5c6354c09fa7840" withDescription:@"怡康乐购物商城"];
    
    
    
    
    //[UMSocialSinaHandler openSSOWithRedirectURL:@"http://112.124.115.55/html/index.html"];
//    [UMSocialQQHandler setQQWithAppId:@"100424468" appKey:@"c7394704798a158208a74ab60104f0ba" url:@"http://112.124.115.55/html/index.html"];
//    [UMSocialQQHandler setQQWithAppId:@"100424468" appKey:@"c7394704798a158208a74ab60104f0ba" url:@"http://112.124.115.55/html/index.html"];
    
    
    
    [self.window setRootViewController:[ViewManager shareInstance].NavigationController];
    
    // 要使用百度地图，请先启动BaiduMapManager
    //_mapManager = [[BMKMapManager alloc]init];
//    BOOL ret = [_mapManager start:@"X7BUmhWp5KOvpPyDn3mUmuq4Nnee9GxS" generalDelegate:self];
//    if (!ret) {
//        NSLog(@"manager start failed!");
//    }
    
    return YES;
}
							
- (void)configUSharePlatforms
{
    /*
     设置微信的appKey和appSecret
     [微信平台从U-Share 4/5升级说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_1
     */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wxa5c6354c09fa7840" appSecret:@"083cfff84bb08f31eadc97bef9708029" redirectURL:@"http://112.124.115.55/html/index.html"];
    /*
     * 移除相应平台的分享，如微信收藏
     */
    //[[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite)]];
    
    /* 设置分享到QQ互联的appID
     * U-Share SDK为了兼容大部分平台命名，统一用appKey和appSecret进行参数设置，而QQ平台仅需将appID作为U-Share的appKey参数传进即可。
     100424468.no permission of union id
     [QQ/QZone平台集成说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_3
     */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1105954597"/*设置QQ平台的appID*/  appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];
    
    /*
     设置新浪的appKey和appSecret
     [新浪微博集成说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_2
     */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3921700954"  appSecret:@"04b48b094faeb16683c32669824ebdad" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
    
    
}

// 支持所有iOS系统
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    //6.3的新的API调用，是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
    if (!result) {
        // 其他如支付等SDK的回调
    }
    return result;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
    if (!result) {
        // 其他如支付等SDK的回调
    }
    return result;
}

//-(void)gotoMyOrderView
//{
//    for(int index = 0;index <[[ViewManager shareInstance].NavigationController.viewControllers count];index++)
//    {
//        UIViewController *vc =[[ViewManager shareInstance].NavigationController.viewControllers objectAtIndex:index];
//        if([vc isKindOfClass:[YMTTabBarController class]])
//        {
//            [[ViewManager shareInstance].NavigationController popToViewController:vc animated:YES];
//        }
//    }
//    MyOrderController *v = [[MyOrderController alloc] init];
//    v.orderStatus = @"1";
//    v.orderTitle = @"待付款";
//    [[ViewManager shareInstance].NavigationController pushViewController:v animated:YES];
//}

/*
- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    
    //跳转支付宝钱包进行支付，需要将支付宝钱包的支付结果回传给SDK
    if ([url.host isEqualToString:@"safepay"]) {
        [[AlipaySDK defaultService]
         processOrderWithPaymentResult:url
         standbyCallback:^(NSDictionary *resultDic) {
             NSLog(@"result = %@", resultDic);
//             [self gotoMyOrderView];
         }];
        return YES;
        
    }
    if([url.host isEqualToString:@"pay"])
    {
        //return [WXApi handleOpenURL:url delegate:self];
    }
    //return  [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];
//    return  [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];
}
 */

/*
-(void) onResp:(BaseResp*)resp
{
    NSString *strMsg = [NSString stringWithFormat:@"errcode:%d", resp.errCode];
    NSString *strTitle;
    
    if([resp isKindOfClass:[SendMessageToWXResp class]])
    {
        strTitle = [NSString stringWithFormat:@"发送媒体消息结果"];
    }
    if([resp isKindOfClass:[PayResp class]]){
        //支付返回结果，实际支付结果需要去微信服务器端查询
        strTitle = [NSString stringWithFormat:@"支付结果"];
        
        switch (resp.errCode) {
            case WXSuccess:
                strMsg = @"支付结果：成功！";
                NSLog(@"支付成功－PaySuccess，retcode = %d", resp.errCode);
//                [self gotoMyOrderView];
                break;
                
            default:
                strMsg = [NSString stringWithFormat:@"支付结果：失败！retcode = %d, retstr = %@", resp.errCode,resp.errStr];
                NSLog(@"错误，retcode = %d, retstr = %@", resp.errCode,resp.errStr);

//                [self gotoMyOrderView];

//                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
//                [alert show];
                break;
        }
    }

}
*/


- (void)applicationDidBecomeActive:(UIApplication *)application
{
    //[UMSocialSnsService  applicationDidBecomeActive];
}

//- (void)applicationDidBecomeActive:(UIApplication *)application
//{
//    [UMSocialSnsService  applicationDidBecomeActive];
//}

@end
